<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>大家分开收到了疯狂的</title>

		<style type="text/css">
			.box {
				font-size: 30px;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<a href="/zx.html">跳转到咨询页面</a>
      <a href="/index2.html">跳转到咨询页面</a>
		</div>
		<div id="content">
			<ul id="list">

			</ul>
		</div>

		<div id="data" style="display: none;">
			[{"cat_name":"毛衫/内搭","cat_href":"https://s.taobao.com/list?q=%E6%AF%9B%E9%92%88%E7%BB%87%E8%A1%AB&cat=16&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1"},{"cat_name":"毛衣","cat_href":"https://s.taobao.com/list?q=%E6%AF%9B%E8%A1%A3&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&cat=50103035"},{"cat_name":"宽松毛衣","cat_href":"https://s.taobao.com/list?q=%E5%AE%BD%E6%9D%BE%E6%AF%9B%E8%A1%A3&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&cat=50103035"},{"cat_name":"开衫","cat_href":"https://s.taobao.com/list?q=%E5%BC%80%E8%A1%AB&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&cat=50102996&ppath=413%3A800001218"},{"cat_name":"高领毛衫","cat_href":"https://s.taobao.com/list?q=%E9%AB%98%E9%A2%86+%E6%AF%9B%E8%A1%A3&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&cat=50102996&ppath="},{"cat_name":"喇叭袖毛衫","cat_href":"https://s.taobao.com/list?q=%E5%96%87%E5%8F%AD%E8%A2%96&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&ppath=&cat=50103035"},{"cat_name":"打底衫","cat_href":"https://s.taobao.com/list?q=%E6%89%93%E5%BA%95%E8%A1%AB&style=grid&seller_type=taobao&spm=a217f.1215286.1000187.1&cps=yes&cat=50102996"},{"cat_name":"长袖T恤","cat_href":"https://s.taobao.com/list?q=%E9%95%BF%E8%A2%96t%E6%81%A4&cat=16&style=grid&seller_type=taobao&spm=a219r.lm874.1000187.1"}]

		</div>
		<script id="tpl" type="text/html">
  		<li>
        <h2>{{cat_name}}</h2>
        <a href="{{cat_href}}">链接</a>
      </li>
    
    
  </script>
		<a href="/zx.html">就飞快的离开</a>
		<script type="text/javascript">
    render()
    function render(){
      var innerData = document.getElementById("data").innerHTML;
      var tpl = document.getElementById("tpl").innerHTML;
      var data = JSON.parse(innerData);
      var len = data.length;
      var oList = document.getElementById("list");
      var list = '';
      var item;
      
      for(var i = 0; i < len; i++){
        item = data[i];
        list += setTplTohtml(tpl, regTpl, {
          cat_name: item.cat_name,
          cat_href: item.cat_href
        })
      }
    }
    
    function setTplTohtml(tpl, regExp, key){
      return tpl.replace(regExp(), function(node, key){
        return opt[key]
      })
    }
    
    function regTpl(){
    	return new RegExp(/{{(.*?)}}/gim)
    }
    
    
  </script>

		<script type="text/javascript">
			(function() {
				var refer = document.referrer;
				var sosuo = refer.split(".")[1];
				var grep = null;
				var str = null;
				var keyword = null;
				switch (sosuo) {
					case "baidu":
						grep = /wd\=.*\&/i;
						str = refer.match(grep)
						keyword = str.toString().split("=")[1].split("&")[0];
						keyword = decodeURIComponent(keyword);
						break;
					case "sogou":
						grep = /query\=.*\&/i;
						str = refer.match(grep)
						keyword = str.toString().split("=")[1].split("&")[0];
						keyword = decodeURIComponent(keyword);
						break;
					case "so":
						grep = /q\=.*\&/i;
						str = refer.match(grep)
						keyword = str.toString().split("=")[1].split("&")[0];
						keyword = decodeURIComponent(keyword);
						break;
					case "google":
						grep = /&q\=.*\&/i;
						str = refer.match(grep)
						keyword = str.toString().split("&")[1].split("=")[1];
						keyword = decodeURIComponent(keyword);
						break;
					default:
						keyword = '暂未获取关键词';
				}
				var e = keyword;
				var oldUrl = window.location.href;
				// window.location.href = setUrlParam('e',e) 
				var newUrl = setQueStr(oldUrl, "e", e)
				console.log(newUrl)
				console.log(window.location.pathname)

				function setQueStr(url, ref, value) {
					var str = "";
					if (url.indexOf('?') != -1)
						str = url.substr(url.indexOf('?') + 1);
					else
						return url + "?" + ref + "=" + value;
					var returnurl = "";
					var setparam = "";
					var arr;
					var modify = "0";

					if (str.indexOf('&') != -1) {
						arr = str.split('&');

						for (i in arr) {
							if (arr[i].split('=')[0] == ref) {
								setparam = value;
								modify = "1";
							} else {
								setparam = arr[i].split('=')[1];
							}
							returnurl = returnurl + arr[i].split('=')[0] + "=" + setparam + "&";
						}

						returnurl = returnurl.substr(0, returnurl.length - 1);

						if (modify == "0")
							if (returnurl == str)
								returnurl = returnurl + "&" + ref + "=" + value;
					} else {
						if (str.indexOf('=') != -1) {
							arr = str.split('=');

							if (arr[0] == ref) {
								setparam = value;
								modify = "1";
							} else {
								setparam = arr[1];
							}
							returnurl = arr[0] + "=" + setparam;
							if (modify == "0")
								if (returnurl == str)
									returnurl = returnurl + "&" + ref + "=" + value;
						} else
							returnurl = ref + "=" + value;
					}
					return url.substr(0, url.indexOf('?')) + "?" + returnurl;
				}
				history.replaceState(0, 0, newUrl);
			}())
		</script>
		
	</body>
</html>


